unit convcontas;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, DB, DBTables, Grids, DBGrids;

type
  TFconvertecontas = class(TForm)
    DataSource1: TDataSource;
    DataSource2: TDataSource;
    DBGrid1: TDBGrid;
    contasdb: TTable;
    contasdbf: TTable;
    Button1: TButton;
    Button2: TButton;
    contasdbCodigo: TStringField;
    contasdbNome: TStringField;
    contasdbData: TDateField;
    contasdbSaldoinicial: TFloatField;
    contasdbSaldoatual: TFloatField;
    contasdbTipo: TStringField;
    contasdbGrupo: TStringField;
    contasdbfCODI: TSmallintField;
    contasdbfNOME: TStringField;
    contasdbfACUM: TStringField;
    contasdbfSALD: TFloatField;
    contasdbfPREV: TFloatField;
    contasdbfATUA: TFloatField;
    contasdbfDATA: TDateField;
    contasdbfANTERIOR: TFloatField;
    contasdbfDEBITO: TFloatField;
    contasdbfCREDITO: TFloatField;
    DBGrid2: TDBGrid;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Fconvertecontas: TFconvertecontas;

implementation

{$R *.dfm}

procedure TFconvertecontas.Button1Click(Sender: TObject);
var
tipo : string;
codigo : string;
begin
contasdb.open;
contasdb.EmptyTable;
contasdb.open;
contasdbf.open;
contasdbf.First;
while not contasdbf.eof do
begin
 codigo := copy(contasdbfcodi.AsString,1,2) + '00' + copy(contasdbfcodi.AsString,3,2);
 if not contasdb.FindKey([codigo]) then contasdb.Append;
 contasdb.edit;
 contasdbcodigo.value       := codigo;
 contasdbnome.value         := contasdbfnome.value;
 contasdbdata.value         := contasdbfdata.value;
 contasdbsaldoinicial.value := contasdbfsald.value;
 tipo := 'R';
 if (contasdbfacum.value = 'S') then
    tipo := 'P';
 contasdbtipo.value := tipo;
 contasdb.post;
 contasdbf.Next;
end;
contasdb.first;
contasdbf.first;
end;

procedure TFconvertecontas.Button2Click(Sender: TObject);
begin
close;
end;



end.
